package com.ayf.payment.game.api.service.platform.impl;

import com.ayf.payment.game.api.entity.platform.SystemBulletin;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.platform.SystemBulletinMapper;
import com.ayf.payment.game.api.service.platform.SystemBulletinService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SystemBulletinServiceImpl implements SystemBulletinService {

    @Resource
    private SystemBulletinMapper systemBulletinMapper;

    @Override
    public boolean insert(SystemBulletin systemBulletin) {
        return systemBulletinMapper.insertSelective(systemBulletin) > 0;
    }

    @Override
    public boolean delete(String id) {
        if (StringUtils.isBlank(id)) {
            throw new ParameterException("系统公告id不能为空");
        }
        return systemBulletinMapper.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public boolean update(SystemBulletin systemBulletin) {
        if (systemBulletin == null) {
            throw new ParameterException("系统公告信息不能为空");
        }
        if (StringUtils.isBlank(systemBulletin.getId())) {
            throw new ParameterException("系统公告id不能为空");
        }
        return systemBulletinMapper.updateByPrimaryKeySelective(systemBulletin) > 0;
    }

    @Override
    public SystemBulletin selectOne(String id) {
        if (StringUtils.isBlank(id)) {
            throw new ParameterException("系统公告id不能为空");
        }
        return systemBulletinMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SystemBulletin> list() {
        return systemBulletinMapper.list();
    }

    @Override
    public boolean deleteAll() {
        systemBulletinMapper.deleteAll();
        return true;
    }
}
